
var util = function(){
    return {
        sendGET:function(url, callback_succ, callback_error, async){
            var _async = true;
            if(async != null)
                _async = async;
            $.ajax
            ({
                url: BaseUrl+url,
                contentType: "application/json; charset=utf-8",
                type: 'GET',
                dataType: "json",
                timeout: 100000,
                async: _async,
                success: callback_succ,
                error: callback_error
            });

        },
        sendPOST:function(url,body, callback_succ, callback_error, async){
            var _async = true;
            if(async != null)
                _async = async;

            $.ajax
            ({
                url: BaseUrl+url,
                contentType: "application/json; charset=utf-8",
                type: 'POST',
                data: JSON.stringify(body),
                dataType: "json",
                timeout: 100000,
                async: _async,
                success: callback_succ,
                error: callback_error
            });

        },
        getUrlParam: function(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) return unescape(r[2]);
            return null;
        },
        isNullStr: function(val) {
            if (val == null || typeof(val) == "undefined") {
                return true;
            } else {

                if (val.length == 0) {
                    return true;
                } else {
                    return false;
                }
            }
        },
        setLoading:function(show){
            if (show) {
                $("#loading").css('display','block');
            }
            else{
                $("#loading").css('display','none');
            }

        },
        checkEmail:function(email){
            var regemail=/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
            return regemail.test(email);
        },
        checkPhone:function(phone){
            var regph=/^[1][3,4,5,6,7,8][0-9]{9}$/;
            return regph.test(phone);
        },
        checkPassword:function(password){
            var zg = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]*$/;
            return zg.test(password);
        },
        setLocalStorage:function (key,value) {
            var storage = window.localStorage;
            storage.setItem(key,JSON.stringify(value));

        },
        getLocalStorage:function (key) {
            var storage = window.localStorage;
            return JSON.parse(storage.getItem(key));

        },
        removeLocalStorage:function (key) {
            var storage = window.localStorage;
            return storage.removeItem(key);

        }
    };
}();
